﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Orders;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class OrderRepositoryTest : RepositoryTestsBase<Order>
    {
       public override System.Linq.Expressions.Expression<Func<Order, bool>> FilterExpression
        {
            get { return a => a.OrderId == TestConstants.Instance.ORDER_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<Order, Guid>> OrderByExpression
        {
            get { return a => a.OrderId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindOrder_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IOrderRepository repository = new OrderRepository(context,traceManager);

            //Act
            repository.FindOrder(null);
        }
			
		[TestMethod()]
        public void FindOrder_Invoke_InvalidIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IOrderRepository repository = new OrderRepository(context, traceManager);

			Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            OrderOrderIdSpecification spec = new OrderOrderIdSpecification(invalidId);

            //Act
            Order order = repository.FindOrder(spec);

            //Assert
            Assert.IsNull(order);
        }
		
        [TestMethod()]
        public void FindOrderById_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IOrderRepository repository = new OrderRepository(context, traceManager);

            OrderOrderIdSpecification spec = new OrderOrderIdSpecification(TestConstants.Instance.ORDER_ID);

            //Act
            Order order = repository.FindOrder(spec);

            //Assert
            Assert.IsNotNull(order);
        }
    }
}
